package manager

import (
	"NovelBook/logic/book"
	"NovelBook/utils/auth"
	"NovelBook/utils/response"
	"github.com/gin-gonic/gin"
	"net/http"
)

// GetAllBooks 获取所有书籍信息
//
//	@Summary		获取所有书籍信息
//	@Description	获取所有书籍信息
//	@Tags			Manager
//	@Accept			json
//	@Produce		json
//	@Security		ApiKeyAuth
//	@Param			Authorization	header		string							true	"`Bearer Token` 使用空格分隔`Bearer`与`Token`"
//	@Success		200				{object}	msg.Code1000{data=[]models.Books}	"获取成功"
//	@Failure		400				{object}	msg.Code1001					"请求参数错误"
//	@Failure		401				{object}	msg.Code1005					"无效的`Token`"
//	@Failure		500				{object}	msg.Code1003					"系统繁忙，请稍后再试"
//	@Router			/manager/books/info-all [get]
func GetAllBooks(c *gin.Context) {
	idAny, exist := c.Get(auth.ManagerIDKey)
	id := idAny.(uint)
	if !exist || id < 1 {
		response.Fail(c, http.StatusUnauthorized, response.CodeTokenInvalid)
		return
	}

	books, err := book.GetBooks()
	if err != nil {
		response.FailWithMsg(c, http.StatusInternalServerError, response.CodeSystemBusy, "system busy")
		return
	}
	response.Success(c, books)
}
